EXERCISE 5: This program has 3 different functions that are almost the same. Let's refactor it to use one function!

  • Create a Custom Block and store the four lines of code under fly_high() within it (lines 6-9).
  • Create a function and name it fly with two parameters: the integer fly_height to control how high the toucan flies and the string fly_type to control what the toucan says.
  • Use the new function to have the toucan do the same series of flights as before: high, high, low, medium, low.

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)